package org.example.aliyun;

import com.alibaba.fastjson.JSON;
import com.aliyun.dysmsapi20170525.models.QuerySendDetailsRequest;
import com.aliyun.dysmsapi20170525.models.QuerySendDetailsResponse;
import com.aliyun.dysmsapi20170525.models.QuerySendDetailsResponseBody;
import com.aliyun.teaopenapi.models.Config;

import java.util.Arrays;

/**
 * @author scout.du
 * @date 2025/10/15 13:53
 **/
public class QuerySample {

    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config();
        config.accessKeyId = accessKeyId;
        config.accessKeySecret = accessKeySecret;
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    public static void main(String[] args_) throws Exception {
//        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.dysmsapi20170525.Client client = QuerySample.createClient("LTAI5tRhVCzuZ9R7wCFq92TX", "1MXAKBxGKWXBNUwObnYzLyQ4kbO0gx");
        // 1.发送短信
//        SendSmsRequest sendReq = new SendSmsRequest()
//                .setPhoneNumbers(args.get(0))
//                .setSignName(args.get(1))
//                .setTemplateCode(args.get(2))
//                .setTemplateParam(args.get(3));
//        SendSmsResponse sendResp = client.sendSms(sendReq);
//        String code = sendResp.body.code;
//        if (!com.aliyun.teautil.Common.equalString(code, "OK")) {
//            com.aliyun.teaconsole.Client.log("错误信息: " + sendResp.body.message + "");
//            return ;
//        }
//
//        String bizId = sendResp.body.bizId;
//        // 2. 等待 10 秒后查询结果
//        com.aliyun.teautil.Common.sleep(10000);
        // 3.查询结果
//        java.util.List<String> phoneNums = com.aliyun.darabonbastring.Client.split(args.get(0), ",", -1);
        java.util.List<String> phoneNums = Arrays.asList("18217542412");
        for (String phoneNum : phoneNums) {
            QuerySendDetailsRequest queryReq = new QuerySendDetailsRequest()
                    .setPhoneNumber(com.aliyun.teautil.Common.assertAsString(phoneNum))
                    .setBizId("693119261102824439^0")
                    .setSendDate(com.aliyun.darabonbatime.Client.format("yyyyMMdd"))
                    .setPageSize(10L)
                    .setCurrentPage(1L);
            QuerySendDetailsResponse queryResp = client.querySendDetails(queryReq);
            java.util.List<QuerySendDetailsResponseBody.QuerySendDetailsResponseBodySmsSendDetailDTOsSmsSendDetailDTO> dtos = queryResp.body.smsSendDetailDTOs.smsSendDetailDTO;
            // 打印结果
            for (QuerySendDetailsResponseBody.QuerySendDetailsResponseBodySmsSendDetailDTOsSmsSendDetailDTO dto : dtos) {
                System.out.println(JSON.toJSONString(dto, true));
//                if (com.aliyun.teautil.Common.equalString("" + dto.sendStatus + "", "3")) {
//                    com.aliyun.teaconsole.Client.log("" + dto.phoneNum + " 发送成功，接收时间: " + dto.receiveDate + "");
//                } else if (com.aliyun.teautil.Common.equalString("" + dto.sendStatus + "", "2")) {
//                    com.aliyun.teaconsole.Client.log("" + dto.phoneNum + " 发送失败");
//                } else {
//                    com.aliyun.teaconsole.Client.log("" + dto.phoneNum + " 正在发送中...");
//                }

            }
        }
    }
}
